<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <#include "/pubHeadStyleTree.html">
    <script type="text/javascript" src="${ctx}/workflowStatic/js/javacode/codemirror.js"></script>
    <script type="text/javascript" src="${ctx}/workflowStatic/js/javacode/InitMirror.js"></script>
    <script type="text/javascript" src="${ctx}/workflowStatic/js/commonScript.js"></script>
    <link href="${ctx}/workflowStatic/style/css/workflow.css" rel="stylesheet">
</head>
<body>
<#assign preModel=map.type1>
<#assign afterModel=map.type2>
<#assign scrptModel=map.type3>
<#assign signScriptModel=map.type5>

<#assign preBeforeModel=map.type5>
<#assign afterBeforeModel=map.type6>

<form id="bpmNodeScriptForm" method="post">
<#if type=="StartEvent">
<div class="layui-tab layui-tab-brief">
    <ul class="layui-tab-title">
        <li class="layui-this">开始事件</li>
    </ul>
    <div class="layui-tab-content">
        <div class="layui-tab-item layui-show">
            <table class="table-detail" cellpadding="0" cellspacing="0" border="0">
                <tr>
                    <th width="20%">说明:<span>*</span> </th>
                    <td>
                        该脚本在流程启动时执行，用户可以使用<span class="red">execution</span>做操作。
                        例如设置流程变量:execution.setVariable("total", 100);
                        <input type="hidden"  name="scriptType" value="1" />
                    </td>
                </tr>
                <tr>
                    <th width="20%" >脚本:<span>*</span> </th>
                    <td>
                        <div>
                            <span class="commonScript" style="cursor: pointer;">
                                <i class="layui-icon layui-icon-fonts-code"></i>常用脚本
                            </span>
                            &nbsp;
                            表单变量:
                            <select name="flowVars" class="flowVars">
                                <option value="">请选择</option>
                            </select>
                        </div>
                        <textarea name="script" codemirror="true" mirrorheight="200px" rows="10" cols="80" >${preModel}</textarea>
                    </td>
                </tr>
            </table>
        </div>
    </div>
</div>
<#elseif type=="SubProcess">
<div class="layui-tab layui-tab-brief">
        <ul class="layui-tab-title">
            <li class="layui-this">开始事件</li>
            <li>结束事件</li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <table class="table-detail" cellpadding="0" cellspacing="0" border="0">
                    <tr>
                        <th width="20%">说明:<span>*</span> </th>
                        <td>
                            该脚本在流程启动时执行，用户可以使用<span class="red">execution</span>做操作。
                            例如设置流程变量:execution.setVariable("total", 100);
                            <input type="hidden"  name="scriptType" value="1" />
                        </td>
                    </tr>
                    <tr>
                        <th width="20%" >脚本:<span>*</span> </th>
                        <td>
                            <div>
                            <span class="commonScript" style="cursor: pointer;">
                                <i class="layui-icon layui-icon-fonts-code"></i>常用脚本
                            </span>
                                &nbsp;
                                表单变量:
                                <select name="flowVars" class="flowVars">
                                    <option value="">请选择</option>
                                </select>
                            </div>
                            <textarea  name="script" codemirror="true" mirrorheight="200px" rows="10" cols="80" >${preModel}</textarea>
                        </td>
                    </tr>
                </table>
            </div>
            <div class="layui-tab-item">
                <table class="table-detail" cellpadding="0" cellspacing="0" border="0"  >
                    <tr>
                        <th width="20%">说明:<span>*</span> </th>
                        <td>
                            该脚本在<span class="red">流程结束</span>时执行，用户可以使用<span class="red">execution</span>做操作。
                            例如设置流程变量:execution.setVariable("total", 100);
                            <input type="hidden"   name="scriptType" value="2"  />
                        </td>
                    </tr>
                    <tr>
                        <th width="20%" >脚本:<span>*</span> </th>
                        <td>
                            <div>
                                <a href="javascript:;"  class="link var" title="常用脚本" onclick="slectScript('endScript')">常用脚本</a>
                                表单变量:
                            </div>
                            <textarea  name="script" codemirror="true" mirrorheight="200px" rows="10" cols="80"  >${afterModel}</textarea>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
</div>
<#elseif type=="EndEvent">
<div class="layui-tab layui-tab-brief">
    <ul class="layui-tab-title">
        <li class="layui-this">结束事件</li>
    </ul>
    <div class="layui-tab-content">
        <div class="layui-tab-item layui-show">
            <table class="table-detail" cellpadding="0" cellspacing="0" border="0"  >
                <tr>
                    <th width="20%">说明:<span>*</span> </th>
                    <td>
                        该脚本在<span class="red">流程结束</span>时执行，用户可以使用<span class="red">execution</span>做操作。
                        例如设置流程变量:execution.setVariable("total", 100);
                        <input type="hidden"   name="scriptType" value="2"  />
                    </td>
                </tr>
                <tr>
                    <th width="20%" >脚本:<span>*</span> </th>
                    <td>
                        <div>
                            <span class="commonScript" style="cursor: pointer;">
                                <i class="layui-icon layui-icon-fonts-code"></i>常用脚本
                            </span>
                            &nbsp;
                            表单变量:
                            <select name="flowVars" class="flowVars">
                                <option value="">请选择</option>
                            </select>
                        </div>
                        <textarea  name="script" codemirror="true" mirrorheight="200px" rows="10" cols="80"  >${afterModel}</textarea>
                    </td>
                </tr>
            </table>
        </div>
    </div>
</div>
<#elseif type=="ScriptTask">
<div class="layui-tab layui-tab-brief">
    <ul class="layui-tab-title">
        <li class="layui-this">脚本代码</li>
    </ul>
    <div class="layui-tab-content">
        <div class="layui-tab-item layui-show">
            <table class="table-detail" cellpadding="0" cellspacing="0" border="0" >
                <tr>
                    <th width="20%">说明:<span>*</span> </th>
                    <td>
                        这个在脚本任务触发时执行，用户可以使用<span class="red">execution</span>做操作。
                        例如设置流程变量:execution.setVariable("total", 100);
                        <input type="hidden"  name="scriptType" value="3"  />
                    </td>
                </tr>
                <tr>
                    <th width="20%" >脚本节点:<span>*</span> </th>
                    <td>
                        <div>
                            <span class="commonScript" style="cursor: pointer;">
                                <i class="layui-icon layui-icon-fonts-code"></i>常用脚本
                            </span>
                            &nbsp;
                            表单变量:
                            <select name="flowVars" class="flowVars">
                                <option value="">请选择</option>
                            </select>
                        </div>
                        <textarea  name="script" codemirror="true" mirrorheight="200px" rows="10" cols="80" >${script}</textarea>
                    </td>
                </tr>
            </table>
        </div>
    </div>
</div>
<#elseif type=="UserTask">
 <div class="layui-tab layui-tab-brief">
     <ul class="layui-tab-title">
         <li class="layui-this">任务创建前置脚本</li>
         <li >任务创建后置脚本</li>
         <li >任务结束前置脚本</li>
         <li >任务结束后置脚本</li>
     </ul>
     <div class="layui-tab-content">
         <div class="layui-tab-item layui-show">
             <table class="table-detail" cellpadding="0" cellspacing="0" border="0">
                 <tr>
                     <th width="20%">说明:<span>*</span> </th>
                     <td>
                         该事件在<span class="red">启动该任务</span>时执行，用户可以使用<span class="red">task</span>做操作。
                         例如设置流程变量:task.setVariable("total", 100);
                         <input type="hidden"  name="scriptType" value="5"  />

                     </td>
                 </tr>
                 <tr>
                     <th width="20%" >脚本:<span>*</span> </th>
                     <td>
                         <div>
                            <span class="commonScript" style="cursor: pointer;">
                                <i class="layui-icon layui-icon-fonts-code"></i>常用脚本
                            </span>
                             &nbsp;
                             表单变量:
                             <select name="flowVars" class="flowVars">
                                 <option value="">请选择</option>
                             </select>
                         </div>
                         <textarea  name="script" codemirror="true" mirrorheight="200px" rows="10" cols="80"  >${preBeforeModel}</textarea>
                     </td>
                 </tr>
             </table>
         </div>
         <div class="layui-tab-item">
             <table class="table-detail" cellpadding="0" cellspacing="0" border="0">
                 <tr>
                     <th width="20%">说明:<span>*</span> </th>
                     <td>
                         该事件在<span class="red">启动该任务</span>时执行，用户可以使用<span class="red">task</span>做操作。
                         例如设置流程变量:task.setVariable("total", 100);
                         <input type="hidden"  name="scriptType" value="1"  />

                     </td>
                 </tr>
                 <tr>
                     <th width="20%" >脚本:<span>*</span> </th>
                     <td>
                         <div>
                            <span class="commonScript" style="cursor: pointer;">
                                <i class="layui-icon layui-icon-fonts-code"></i>常用脚本
                            </span>
                             &nbsp;
                             表单变量:
                             <select name="flowVars" class="flowVars">
                                 <option value="">请选择</option>
                             </select>
                         </div>
                         <textarea  name="script" codemirror="true" mirrorheight="200px" rows="10" cols="80"  >${preModel}</textarea>
                     </td>
                 </tr>
             </table>
         </div>
         <div class="layui-tab-item">
             <table class="table-detail" cellpadding="0" cellspacing="0" border="0">
                 <tr>
                     <th width="20%">说明:<span>*</span> </th>
                     <td>
                         该事件在<span class="red">任务完成</span>时执行，用户可以使用<span class="red">task</span>做操作。
                         例如设置流程变量:task.setVariable("total", 100);
                         <input type="hidden"   name="scriptType" value="6" />

                     </td>
                 </tr>
                 <tr>
                     <th width="20%">脚本:<span>*</span>  </th>
                     <td>
                         <div>
                            <span class="commonScript" style="cursor: pointer;">
                                <i class="layui-icon layui-icon-fonts-code"></i>常用脚本
                            </span>
                             &nbsp;
                             表单变量:
                             <select name="flowVars" class="flowVars">
                                 <option value="">请选择</option>
                             </select>
                         </div>
                         <textarea  name="script" codemirror="true" mirrorheight="200px" rows="10" cols="80" >${afterBeforeModel}</textarea>
                     </td>
                 </tr>
             </table>
         </div>
         <div class="layui-tab-item">
             <table class="table-detail" cellpadding="0" cellspacing="0" border="0">
                 <tr>
                     <th width="20%">说明:<span>*</span> </th>
                     <td>
                         该事件在<span class="red">任务完成</span>时执行，用户可以使用<span class="red">task</span>做操作。
                         例如设置流程变量:task.setVariable("total", 100);<br>
                         approvalStatus_${nodeId}=1为通过;2为反对。
                         <input type="hidden"   name="scriptType" value="2" />

                     </td>
                 </tr>
                 <tr>
                     <th width="20%">脚本:<span>*</span>  </th>
                     <td>
                         <div>
                            <span class="commonScript" style="cursor: pointer;">
                                <i class="layui-icon layui-icon-fonts-code"></i>常用脚本
                            </span>
                             &nbsp;
                             表单变量:
                             <select name="flowVars" class="flowVars">
                                 <option value="">请选择</option>
                             </select>
                         </div>
                         <textarea  name="script" codemirror="true" mirrorheight="200px" rows="10" cols="80" >${afterModel}</textarea>
                     </td>
                 </tr>
             </table>
         </div>
     </div>
 </div>
<#elseif type=="SignExecuteScript">
<div class="layui-tab layui-tab-brief">
    <ul class="layui-tab-title">
        <li class="layui-this">开始事件</li>
    </ul>
    <div class="layui-tab-content">
        <div class="layui-tab-item layui-show">
            <table class="table-detail" cellpadding="0" cellspacing="0" border="0">
                <tr>
                    <th width="20%">说明:<span>*</span> </th>
                    <td>
                        该脚本在判断会签是否结束时执行，用户可以使用<span class="red">execution</span>做操作。
                        例如设置流程变量:execution.setVariable("total", 100);
                        也可以使用<span class="red">isCompleted</span>判断会签是否结束;<br/>
                        <pre>例如：if(isCompleted){</pre>
                        <pre>	execution.setVariable("total", 100);</pre>
                        <pre>}
						</pre>
                        <input type="hidden"  name="scriptType" value="5"  class="inputText"/>
                    </td>
                </tr>
                <tr>
                    <th width="20%" >脚本:<span>*</span> </th>
                    <td>
                        <div class="workflowIndex layui-inline">
                            <label class="layui-form-label"><i class="layui-icon layui-icon-fonts-code"></i>常用脚本 表单变量:</label>
                            <!--<span class="commonScript" style="cursor: pointer;">-->
                                <!--<i class="layui-icon layui-icon-fonts-code"></i>常用脚本-->
                            <!--</span>-->
                            <!--&nbsp;-->
                            <!--表单变量:-->
                            <!--<select name="flowVars" class="flowVars" lay-filter="flowVars">-->
                                <!--<option value="">请选择</option>-->
                            <!--</select>-->
                            <div class="layui-input-inline">
                                <select name="flowVars" lay-verify="required" class="flowVars">
                                    <option value="">请选择</option>
                                </select>
                            </div>
                        </div>
                        <textarea  name="script" codemirror="true" mirrorheight="200px" rows="10" cols="80" >${signScriptModel}</textarea>
                    </td>
                </tr>
            </table>
        </div>
    </div>
</div>
</#if>
<input type="hidden" id="nodeId" name="nodeId" value="${nodeId}" />
<input type="hidden" id="procDefId" name="procDefId" value="${procDefId}"/>
<input type="hidden" id="modelId" name="modelId" value="${modelId}"/>
<input type="hidden" id="parentProcDefId" name="parentProcDefId" value="${parentProcDefId}"/>
<input type="hidden" id="type" value="${type}">
</form>
<script>
    layui.config({
        base: serverPath.systemPath + staticPath.systemPath //静态资源所在路径
    }).extend({
        index: 'index' //主入口模块
    }).use(['index','form','jquery','setter'], function(){
        var form = layui.form;
        var $ = layui.$;
        var setter = layui.setter;
        saveS = function(){
            InitMirror.save();
            var url = serverPath.workflowPath+"/workflow/bpmNodeScript/save";
            var type = $("#type").val();
            if(type == "ScriptTask"){
                url = serverPath.workflowPath+"/workflow/bpmNodeScript/saveScriptInModel";
            }
            var para = $('#bpmNodeScriptForm').serialize();
            $.ajax({
                url: url,
                type: "POST",
                dataType:"json",
                data: para,
                success: function (data) {
                    if (data.code==0) {
                        window.parent.layer.alert(data.msg, function (index) {
                            parent.layer.closeAll(); //关闭所有页面层
                        });
                    } else {
                        window.parent.layer.alert(data.msg);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    layer.alert("保存失败！" + XMLHttpRequest.status);
                },
            });
        };
    })
</script>
<script type="text/javascript" src="${ctx}/workflowStatic/js/flowVars.js"></script>
</body>
</html>
